//
//  TZDiscoverTableViewController.m
//  wangYiCaiPiao
//
//  Created by mac on 16/1/4.
//  Copyright © 2016年 tz. All rights reserved.
//

#import "TZDiscoverTableViewController.h"
#import "TZDiscoverTableViewCell.h"
#import "TZDisCoverModel.h"
#import "TZBuyViewController.h"
#import "TZLuckViewController.h"
#import "TZjoySquareController.h"
#import "TZNewsController.h"


@interface TZDiscoverTableViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSArray *array;
@end

@implementation TZDiscoverTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationItem setTitle:@"发现"];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    [self.view addSubview:tableView];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.rowHeight = 80;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TZDiscoverTableViewCell *cell = [TZDiscoverTableViewCell settingCellWithTableview:tableView];
    cell.model = self.array[indexPath.section];
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    TZBuyViewController *buyViewController = [[TZBuyViewController alloc] init];
    TZjoySquareController *joySquareController = [[TZjoySquareController alloc] init];
    TZLuckViewController *luckViewController = [[TZLuckViewController alloc] init];
    TZNewsController *newsController = [[TZNewsController alloc] init];
    //页面跳转
    if (indexPath.section == 0) {
        [self.navigationController pushViewController:buyViewController animated:YES];
    } else if (indexPath.section == 1) {
        [self.navigationController pushViewController:joySquareController animated:YES];
    } else if (indexPath.section == 2) {
        [self.navigationController pushViewController:luckViewController animated:YES];
    } else {
        [self.navigationController pushViewController:newsController animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 15;
}

//懒加载
- (NSArray *)array {
    if (_array == nil) {
        NSArray *tempArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"TZDiscoverTableViewCell.plist" ofType:nil]];
        NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:tempArray.count];
        for (NSDictionary *dict in tempArray) {
            TZDisCoverModel *model = [TZDisCoverModel dicscoverWithDict:dict];
            [mArray addObject:model];
        }
        _array = mArray;
    }
    return _array;
}
@end
